import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
from joblib import load

class NN(object):
    
    def  __init__(self):
        self.loaded_model = tf.keras.models.load_model('NN/my_model.keras')
        self.scaler = load('NN/scaler.joblib')
        
    def get_hourly_trend(self):
        """获取测试结果
        """
        n_steps = 7
        df_pivot = pd.read_csv('./NN/scenic_data.csv')
        latest_data = df_pivot.iloc[-n_steps:].values
        
        # 确保输入数据的形状与模型训练时的形状一致
        expected_shape = (1, n_steps, self.loaded_model.input_shape[-1])
        latest_data = latest_data.reshape(expected_shape)
        
        predicted = self.loaded_model.predict(latest_data)
        predicted_counts = self.scaler.inverse_transform(predicted)
        predicted_counts[predicted_counts < 0] = 0
        
        hourly_trend = predicted_counts[0].astype(int).tolist()
        print(hourly_trend)
        
if __name__ == '__main__':
    nn = NN()
    nn.get_hourly_trend()